<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/*
 * ajax返回
 * 
 * @param int $ret_id 错误代码
 * @param str $ret_msg 错误提示信息
 * @param array $ret_data 返回值
 * 
 * @return json
 */
if(!function_exists('ret_msg')){
    function ret_msg($ret_id=0,$ret_data=null){
        include  __DIR__.'/constant.php';
        $array['errcode']   =$ret_id;
        $array['msg']       =constant('ERR_'.$ret_id);
        $array['data']      =$ret_data;
        echo json_encode($array);
        exit;
    }
}

/*
 * 根据ID获取节点字段
 * 
 * @param int $node_id 节点ID
 * @param str $field 需要获取的字段
 * @return str nadeName 节点名称
 */
if(!function_exists('getNodeName')){
    function getNodeName($node_id='',$field='name'){
        if(empty($node_id)){
            return "<span style='color:blue'>顶级节点</span>";
        }
        return think\Db::name('Node')->where(array("id"=>$node_id))->value($field);
    }
}